package com.ruoyi.drugSystem.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.drugSystem.domain.SysDrugStock;
import com.ruoyi.drugSystem.mapper.SysDrugStockMapper;
import com.ruoyi.drugSystem.service.ISysDrugStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 仓库Service业务层处理
 *
 * @author ruoyi
 * @date 2023-03-08
 */
@Service
public class SysDrugStockServiceImpl implements ISysDrugStockService
{
    @Autowired
    private SysDrugStockMapper sysDrugStockMapper;

    /**
     * 查询仓库
     *
     * @param stockId 仓库主键
     * @return 仓库
     */
    @Override
    public SysDrugStock selectSysDrugStockByStockId(Long stockId)
    {
        return sysDrugStockMapper.selectSysDrugStockByStockId(stockId);
    }

    /**
     * 查询仓库列表
     *
     * @param sysDrugStock 仓库
     * @return 仓库
     */
    @Override
    public List<SysDrugStock> selectSysDrugStockList(SysDrugStock sysDrugStock)
    {
        return sysDrugStockMapper.selectSysDrugStockList(sysDrugStock);
    }

    /**
     * 校验仓库名称是否唯一
     *
     * @param drugStock 仓库信息
     * @return 结果
     */
    @Override
    public boolean checkDrugStockNameUnique(SysDrugStock drugStock)
    {
        Long drugStockId = StringUtils.isNull(drugStock.getStockId()) ? -1L : drugStock.getStockId();
        SysDrugStock info = sysDrugStockMapper.checkDrugStockNameUnique(drugStock.getStockName());
        if (StringUtils.isNotNull(info) && info.getStockId().longValue() != drugStockId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 校验仓库编码是否唯一
     *
     * @param drugStock 仓库信息
     * @return 结果
     */
    @Override
    public boolean checkDrugStockCodeUnique(SysDrugStock drugStock)
    {
        Long drugStockId = StringUtils.isNull(drugStock.getStockId()) ? -1L : drugStock.getStockId();
        SysDrugStock info = sysDrugStockMapper.checkDrugStockCodeUnique(drugStock.getStockCode());
        if (StringUtils.isNotNull(info) && info.getStockId().longValue() != drugStockId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 新增仓库
     *
     * @param sysDrugStock 仓库
     * @return 结果
     */
    @Override
    public int insertSysDrugStock(SysDrugStock sysDrugStock)
    {
        return sysDrugStockMapper.insertSysDrugStock(sysDrugStock);
    }

    /**
     * 修改仓库
     *
     * @param sysDrugStock 仓库
     * @return 结果
     */
    @Override
    public int updateSysDrugStock(SysDrugStock sysDrugStock)
    {
        return sysDrugStockMapper.updateSysDrugStock(sysDrugStock);
    }

    /**
     * 批量删除仓库
     *
     * @param stockIds 需要删除的仓库主键
     * @return 结果
     */
    @Override
    public int deleteSysDrugStockByStockIds(Long[] stockIds)
    {
        return sysDrugStockMapper.deleteSysDrugStockByStockIds(stockIds);
    }

    /**
     * 删除仓库信息
     *
     * @param stockId 仓库主键
     * @return 结果
     */
    @Override
    public int deleteSysDrugStockByStockId(Long stockId)
    {
        return sysDrugStockMapper.deleteSysDrugStockByStockId(stockId);
    }
}
